home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / XSHP15.ARJ / INITCUBE.C < prev    next >
Text File  |  1992-01-05  |  6KB  |  123 lines

  1. /* Initializes the cubes and adds them to the object list. */
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "polygon.h"
  5.  
  6. #define NUM_CUBES 11             /* # of cubes */
  7. Point3 CubeVerts[NUM_CUBE_VERTS]; /* set elsewhere, from floats */
  8. /* Vertex indices for individual cube faces */
  9. static int Face1[] = {1,3,2,0};
  10. static int Face2[] = {5,7,3,1};
  11. static int Face3[] = {4,5,1,0};
  12. static int Face4[] = {3,7,6,2};
  13. static int Face5[] = {5,4,6,7};
  14. static int Face6[] = {0,2,6,4};
  15. static int *VertNumList[]={Face1, Face2, Face3, Face4, Face5, Face6};
  16. static int VertsInFace[]={ sizeof(Face1)/sizeof(int),
  17.    sizeof(Face2)/sizeof(int), sizeof(Face3)/sizeof(int),
  18.    sizeof(Face4)/sizeof(int), sizeof(Face5)/sizeof(int),
  19.    sizeof(Face6)/sizeof(int) };
  20. /* X, Y, Z rotations for cubes, in tenths of degrees (angles) */
  21. static RotateControl InitialRotate[NUM_CUBES] = {
  22.    {0,60,60}, {30,0,30}, {30,30,0},
  23.    {-30,20,0},{-60,-30,0},
  24.    {30,0,-60},{-20,0,30},{-30,0,-30},
  25.    {0,20,-20},{0,-30,30},{0,-60,-60},};
  26. static MoveControl InitialMove[NUM_CUBES] = {
  27.    {0,0,75,0,0,-6000,0,0,-350},{0,0,45,0,0,-6000,0,0,-350},
  28.    {0,0,50,0,0,-6000,0,0,-350},{0,0,90,0,0,-6000,0,0,-350},
  29.    {0,0,60,0,0,-6000,0,0,-350},
  30.    {0,0,100,0,0,-6000,0,0,-350},{0,0,70,0,0,-6000,0,0,-350},
  31.    {0,0,40,0,0,-6000,0,0,-350},{0,0,80,0,0,-6000,0,0,-350},
  32.    {0,0,55,0,0,-6000,0,0,-350},{0,0,65,0,0,-6000,0,0,-350}, };
  33. /* Face colors for various cubes */
  34. static int Colors[NUM_CUBES][NUM_CUBE_FACES] = {
  35.    {15,14,12,11,10,9},{1,2,3,4,5,6},{35,37,39,41,43,45},
  36.    {47,49,51,53,55,57},{71,73,75,77,79,81},
  37.    {83,85,87,89,91,93},{95,97,99,101,103,105},
  38.    {107,109,111,113,115,117},{119,121,123,125,127,129},
  39.    {131,133,135,137,139,141},{143,145,147,149,151,153} };
  40. /* Starting coordinates for cubes in world space */
  41. static int CubeStartCoords[NUM_CUBES][3] = {
  42.    {90,0,-6000},  {90,60,-6000}, {90,-60,-6000}, {30,60,-6000},
  43.    {30,-60,-6000}, {-30,0,-6000},   {-30,60,-6000},
  44.    {-30,-60,-6000},{-90,0,-6000}, {-90,60,-6000}, {-90,-60,-6000}};
  45. /* Delay counts (speed control) for cubes */
  46. static int InitRDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
  47. static int BaseRDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
  48. static int InitMDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
  49. static int BaseMDelayCounts[NUM_CUBES] = {1,1,1,1,1,1,1,1,1,1,1};
  50.  
  51. void InitializeCubes()
  52. {
  53.    int i, j, k;
  54.    PObject *WorkingCube;
  55.  
  56.    for (i=0; i<NUM_CUBES; i++) {
  57.       if ((WorkingCube = malloc(sizeof(PObject))) == NULL) {
  58.          printf("Couldn't get memory\n"); exit(1); }
  59.       WorkingCube->DrawFunc = DrawPObject;
  60.       WorkingCube->RecalcFunc = XformAndProjectPObject;
  61.       WorkingCube->MoveFunc = RotateAndMovePObject;
  62.       WorkingCube->RecalcXform = 1;
  63.       for (k=0; k<2; k++) {
  64.          WorkingCube->EraseRect[k].Left =
  65.             WorkingCube->EraseRect[k].Top = 0x7FFF;
  66.          WorkingCube->EraseRect[k].Right = 0;
  67.          WorkingCube->EraseRect[k].Bottom = 0;
  68.       }
  69.       WorkingCube->RDelayCount = InitRDelayCounts[i];
  70.       WorkingCube->RDelayCountBase = BaseRDelayCounts[i];
  71.       WorkingCube->MDelayCount = InitMDelayCounts[i];
  72.       WorkingCube->MDelayCountBase = BaseMDelayCounts[i];
  73.       /* Set the object->world xform to none */
  74.       for (j=0; j<3; j++)
  75.          for (k=0; k<4; k++)
  76.             WorkingCube->XformToWorld[j][k] = INT_TO_FIXED(0);
  77.       WorkingCube->XformToWorld[0][0] = 
  78.          WorkingCube->XformToWorld[1][1] =
  79.          WorkingCube->XformToWorld[2][2] = INT_TO_FIXED(1);
  80.       /* Set the initial location */
  81.       for (j=0; j<3; j++) {
  82.             WorkingCube->XformToWorld[j][3] =
  83.                   INT_TO_FIXED(CubeStartCoords[i][j]);
  84.       }
  85.       /* Initial center coordinates */
  86.       WorkingCube->CenterInView.X = WorkingCube->XformToWorld[0][3];
  87.       WorkingCube->CenterInView.Y = WorkingCube->XformToWorld[1][3];
  88.       WorkingCube->CenterInView.Z = WorkingCube->XformToWorld[2][3];
  89.       WorkingCube->NumVerts = NUM_CUBE_VERTS;
  90.       WorkingCube->VertexList = CubeVerts;
  91.       WorkingCube->NumFaces = NUM_CUBE_FACES;
  92.       WorkingCube->Rotate = InitialRotate[i];
  93.       WorkingCube->Move.MoveX = INT_TO_FIXED(InitialMove[i].MoveX);
  94.       WorkingCube->Move.MoveY = INT_TO_FIXED(InitialMove[i].MoveY);
  95.       WorkingCube->Move.MoveZ = INT_TO_FIXED(InitialMove[i].MoveZ);
  96.       WorkingCube->Move.MinX = INT_TO_FIXED(InitialMove[i].MinX);
  97.       WorkingCube->Move.MinY = INT_TO_FIXED(InitialMove[i].MinY);
  98.       WorkingCube->Move.MinZ = INT_TO_FIXED(InitialMove[i].MinZ);
  99.       WorkingCube->Move.MaxX = INT_TO_FIXED(InitialMove[i].MaxX);
  100.       WorkingCube->Move.MaxY = INT_TO_FIXED(InitialMove[i].MaxY);
  101.       WorkingCube->Move.MaxZ = INT_TO_FIXED(InitialMove[i].MaxZ);
  102.       if ((WorkingCube->XformedVertexList =
  103.             malloc(NUM_CUBE_VERTS*sizeof(Point3))) == NULL) {
  104.          printf("Couldn't get memory\n"); exit(1); }
  105.       if ((WorkingCube->ProjectedVertexList =
  106.             malloc(NUM_CUBE_VERTS*sizeof(Point3))) == NULL) {
  107.          printf("Couldn't get memory\n"); exit(1); }
  108.       if ((WorkingCube->ScreenVertexList =
  109.             malloc(NUM_CUBE_VERTS*sizeof(Point))) == NULL) {
  110.          printf("Couldn't get memory\n"); exit(1); }
  111.       if ((WorkingCube->FaceList =
  112.             malloc(NUM_CUBE_FACES*sizeof(Face))) == NULL) {
  113.          printf("Couldn't get memory\n"); exit(1); }
  114.       /* Initialize the faces */
  115.       for (j=0; j<NUM_CUBE_FACES; j++) {
  116.          WorkingCube->FaceList[j].VertNums = VertNumList[j];
  117.          WorkingCube->FaceList[j].NumVerts = VertsInFace[j];
  118.          WorkingCube->FaceList[j].Color = Colors[i][j];
  119.       }
  120.       AddObject((Object *)WorkingCube);
  121.    }
  122. }
  123.